package com.sheyu.mall.product.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sheyu.mall.product.dao.attr.AttrAttrgroupRelationDao;
import com.sheyu.mall.product.dao.attr.AttrGroupDao;
import com.sheyu.mall.product.entity.attr.AttrAttrgroupRelationEntity;
import com.sheyu.mall.product.entity.attr.AttrGroupEntity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author sheyu
 * @Desciption:
 * @date 2020/10/10 4:37 下午
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class AttrGroup {

    @Autowired
    private AttrGroupDao attrGroupDao;

    @Autowired
    private AttrAttrgroupRelationDao relationDao;

    @Test
    public void testSelectByCatelogIdBySQL(){
        List<AttrGroupEntity> attrGroupEntityList = attrGroupDao.selectByCatelogIdBySQL(225L);
        System.out.println(attrGroupEntityList);
    }

    @Test
    public void testJoinCatelogAndAttrGroup(){
        List<Long> attrIds = attrGroupDao.joinCatelogAndAttrGroup(225L);
        System.out.println(attrIds);
    }

    @Test
    public void testSingleTable(){
        Long catelogId = 225L;
        List<AttrGroupEntity> groupEntities = attrGroupDao.selectList(new QueryWrapper<AttrGroupEntity>().eq("catelog_id",catelogId));

        //获取分类对应的属性分组
        List<Long> groupIds = groupEntities.stream().map((obj)->{
            return obj.getAttrGroupId();
        }).collect(Collectors.toList());

        List<AttrAttrgroupRelationEntity> attrAttrgroupRelationEntities = relationDao.
                selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", groupIds));
        List<Long> attrIds = attrAttrgroupRelationEntities.stream().map((obj)->{
            return obj.getAttrId();
        }).collect(Collectors.toList());
        System.out.println(attrIds);
    }
}
